<?php
class ModelShippingMultiFlat extends Model {
	function getQuote($address) {
		$this->language->load('shipping/multiflat');
		
		$multiflat_tax_class_id = explode(':', $this->config->get('multiflat_tax_class_id'));
		$multiflat_cost = explode(':', $this->config->get('multiflat_cost'));
		$multiflat_sort_order = explode(':', $this->config->get('multiflat_sort_order'));
		$multiflat_geo_zone_id = explode(':', $this->config->get('multiflat_geo_zone_id'));
		$multiflat_geo_zone_id_count = count($multiflat_geo_zone_id);
		
		for($i = 0; $i < $multiflat_geo_zone_id_count; $i++){
		
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$multiflat_geo_zone_id[$i] . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
		
			if (!$multiflat_geo_zone_id[$i]) {
				$status = true;
			} elseif ($query->num_rows) {
				$status = true;
			} else {
				$status = false;
			}
	
			$method_data = array();
		
			if ($status) {
				$quote_data = array();
				
				$quote_data['multiflat'] = array(
					'code'         => 'multiflat.multiflat',
					'title'        => $this->language->get('text_description'),
					'cost'         => $multiflat_cost[$i],
					'tax_class_id' => $multiflat_tax_class_id[$i],
					'text'         => $this->currency->format($this->tax->calculate($multiflat_cost[$i], $multiflat_tax_class_id[$i], $this->config->get('config_tax')))
				);

				$method_data = array(
					'code'       => 'multiflat',
					'title'      => $this->language->get('text_title'),
					'quote'      => $quote_data,
					'sort_order' => $multiflat_sort_order[$i],
					'error'      => false
				);
				return $method_data;
			}
		}
	}
}
?>